require('./index.css')
var _mm = require('util/mm.js')

var header = {
    init : function(){
        this.bindEvent()
        this.onLoad()
    },
    //组件加载 input搜索词回填
    onLoad : function(){
        var keyword = _mm.getUrlParam('keyword')
        if(keyword){
            $('#search-input').val(keyword)
        }
    },
    bindEvent : function(){
        var _this = this;
        $('#search-btn').click(function(){
                _this.searchSubmit()
        })
        //回车搜索提交
        $('#search-input').keyup(function(e){
            if(e.keyCode===13){
                _this.searchSubmit()
            }
        })
    },
    //搜索提交
    searchSubmit : function(){
        //提交的时候有keyword，正常跳转到list页面并携带keyword参数
        var keyword = $.trim($('#search-input').val())
        if(keyword){
            window.location.href = './list.html?keyword=' + keyword
        }else{
            _mm.goHome()
        }
    }
}
header.init();